package org.example.panel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginPanel extends JPanel {
    private JButton btLogin = new JButton("login");
    private JButton btExit = new JButton("exit");

    public LoginPanel() {

        // 1. 界面，菜单，
        initPanel();
        // 2. 监听 ，数据，
        addListener();
    }

    private void addListener(){
        btLogin.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                LoginPanel.this.goNext();
            }
        });

        btExit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
    }

    private void goNext(){
        JOptionPane.showMessageDialog(this,"press login");

    }

    private void initPanel(){
        this.setLayout(new BorderLayout());
        this.add( new JLabel("登录系统"),BorderLayout.NORTH);
        this.add(setCenterPanel() ,BorderLayout.CENTER);
        this.add(setSouthPanel() ,BorderLayout.SOUTH);
    }

    private JPanel setCenterPanel(){
        JPanel jp = new JPanel(new BorderLayout());
        jp.add( setUserCodePanel() , BorderLayout.NORTH);
        jp.add( setUserPwdPanel(), BorderLayout.SOUTH);
        return jp;
    }

    private JPanel setUserCodePanel(){
        JPanel jp = new JPanel();
        jp.add(new JLabel("用户账号"));
        jp.add(new JTextField(12));
        return jp;
    }

    private JPanel setUserPwdPanel(){
        JPanel jp = new JPanel();
        jp.add(new JLabel("用户密码"));
        jp.add(new JTextField(12));
        return jp;
    }

    private JPanel setSouthPanel(){
        JPanel jp = new JPanel();
        jp.add(btLogin);
        jp.add(btExit);
        return jp;
    }
}
